home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / foodf.c < prev    next >
C/C++ Source or Header  |  2000-05-04  |  6KB  |  241 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. /*
  15.  *        Globals we own
  16.  */
  17.  
  18. size_t foodf_playfieldram_size;
  19. size_t foodf_spriteram_size;
  20.  
  21. unsigned char *foodf_playfieldram;
  22. unsigned char *foodf_spriteram;
  23.  
  24.  
  25. /*
  26.  *        Statics
  27.  */
  28.  
  29. static unsigned char *playfielddirty;
  30.  
  31. static struct osd_bitmap *playfieldbitmap;
  32.  
  33.  
  34. /*
  35.  *        Prototypes from other modules
  36.  */
  37.  
  38. void foodf_vh_stop (void);
  39.  
  40.  
  41. /***************************************************************************
  42.  
  43.   Convert the color PROMs into a more useable format.
  44.  
  45.   Food Fight doesn't have a color PROM. It uses 256 bytes of RAM to
  46.   dynamically create the palette. Each byte defines one
  47.   color (3-3-2 bits per R-G-B).
  48.   Graphics use 2 bitplanes.
  49.  
  50. ***************************************************************************/
  51. void foodf_vh_convert_color_prom (unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  52. {
  53.     int i;
  54.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  55.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  56.  
  57.     for (i = 0;i < Machine->drv->total_colors;i++)
  58.     {
  59.         *(palette++) = ((i & 1) >> 0) * 0xff;
  60.         *(palette++) = ((i & 2) >> 1) * 0xff;
  61.         *(palette++) = ((i & 4) >> 2) * 0xff;
  62.     }
  63.  
  64.     /* characters and sprites use the same palette */
  65.     for (i = 0;i < TOTAL_COLORS(0);i++)
  66.         COLOR(0,i) = i;
  67. }
  68.  
  69.  
  70. /*
  71.  *   video system start; we also initialize the system memory as well here
  72.  */
  73.  
  74. int foodf_vh_start(void)
  75. {
  76.     /* allocate dirty buffers */
  77.     if (!playfielddirty) playfielddirty = malloc (foodf_playfieldram_size / 2);
  78.     if (!playfielddirty)
  79.     {
  80.         foodf_vh_stop ();
  81.         return 1;
  82.     }
  83.     memset (playfielddirty, 1, foodf_playfieldram_size / 2);
  84.  
  85.     /* allocate bitmaps */
  86.     if (!playfieldbitmap) playfieldbitmap = osd_create_bitmap (32*8, 32*8);
  87.     if (!playfieldbitmap)
  88.     {
  89.         foodf_vh_stop ();
  90.         return 1;
  91.     }
  92.  
  93.     return 0;
  94. }
  95.  
  96.  
  97. /*
  98.  *   video system shutdown; we also bring down the system memory as well here
  99.  */
  100.  
  101. void foodf_vh_stop(void)
  102. {
  103.     /* free bitmaps */
  104.     if (playfieldbitmap) osd_free_bitmap (playfieldbitmap); playfieldbitmap = 0;
  105.  
  106.     /* free dirty buffers */
  107.     if (playfielddirty) free (playfielddirty); playfielddirty = 0;
  108. }
  109.  
  110.  
  111. /*
  112.  *   playfield RAM read/write handlers
  113.  */
  114.  
  115. READ_HANDLER( foodf_playfieldram_r )
  116. {
  117.     return READ_WORD (&foodf_playfieldram[offset]);
  118. }
  119.  
  120. WRITE_HANDLER( foodf_playfieldram_w )
  121. {
  122.     int oldword = READ_WORD (&foodf_playfieldram[offset]);
  123.     int newword = COMBINE_WORD (oldword, data);
  124.  
  125.     if (oldword != newword)
  126.     {
  127.         WRITE_WORD (&foodf_playfieldram[offset], newword);
  128.         playfielddirty[offset / 2] = 1;
  129.     }
  130. }
  131.  
  132.  
  133. /*
  134.  *   palette RAM read/write handlers
  135.  */
  136.  
  137. WRITE_HANDLER( foodf_paletteram_w )
  138. {
  139.     int oldword = READ_WORD(&paletteram[offset]);
  140.     int newword = COMBINE_WORD(oldword,data);
  141.     int bit0,bit1,bit2;
  142.     int r,g,b;
  143.  
  144.  
  145.     WRITE_WORD(&paletteram[offset],newword);
  146.  
  147.     /* only the bottom 8 bits are used */
  148.     /* red component */
  149.     bit0 = (newword >> 0) & 0x01;
  150.     bit1 = (newword >> 1) & 0x01;
  151.     bit2 = (newword >> 2) & 0x01;
  152.     r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  153.     /* green component */
  154.     bit0 = (newword >> 3) & 0x01;
  155.     bit1 = (newword >> 4) & 0x01;
  156.     bit2 = (newword >> 5) & 0x01;
  157.     g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  158.     /* blue component */
  159.     bit0 = 0;
  160.     bit1 = (newword >> 6) & 0x01;
  161.     bit2 = (newword >> 7) & 0x01;
  162.     b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  163.  
  164.     palette_change_color(offset / 2,r,g,b);
  165. }
  166.  
  167.  
  168.  
  169. /***************************************************************************
  170.  
  171.   Draw the game screen in the given osd_bitmap.
  172.   Do NOT call osd_update_display() from this function, it will be called by
  173.   the main emulation engine.
  174.  
  175. ***************************************************************************/
  176. void foodf_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  177. {
  178.     int offs;
  179.  
  180.     /* recalc the palette if necessary */
  181.     if (palette_recalc ())
  182.         memset (playfielddirty,1,foodf_playfieldram_size / 2);
  183.  
  184.  
  185.     /* for every character in the Video RAM, check if it has been modified */
  186.     /* since last time and update it accordingly. */
  187.     for (offs = foodf_playfieldram_size - 2; offs >= 0; offs -= 2)
  188.     {
  189.         int data = READ_WORD (&foodf_playfieldram[offs]);
  190.         int color = (data >> 8) & 0x3f;
  191.  
  192.         if (playfielddirty[offs / 2])
  193.         {
  194.             int pict = (data & 0xff) | ((data >> 7) & 0x100);
  195.             int sx,sy;
  196.  
  197.             playfielddirty[offs / 2] = 0;
  198.  
  199.             sx = ((offs/2) / 32 + 1) % 32;
  200.             sy = (offs/2) % 32;
  201.  
  202.             drawgfx (playfieldbitmap, Machine->gfx[0],
  203.                     pict, color,
  204.                     0, 0,
  205.                     8*sx, 8*sy,
  206.                     0,
  207.                     TRANSPARENCY_NONE, 0);
  208.         }
  209.     }
  210.     copybitmap (bitmap, playfieldbitmap, 0, 0, 0, 0, &Machine->drv->visible_area, TRANSPARENCY_NONE, 0);
  211.  
  212.     /* walk the motion object list. */
  213.     for (offs = 0; offs < foodf_spriteram_size; offs += 4)
  214.     {
  215.         int data1 = READ_WORD (&foodf_spriteram[offs]);
  216.         int data2 = READ_WORD (&foodf_spriteram[offs + 2]);
  217.  
  218.         int pict = data1 & 0xff;
  219.         int color = (data1 >> 8) & 0x1f;
  220.         int xpos = (data2 >> 8) & 0xff;
  221.         int ypos = (0xff - data2 - 16) & 0xff;
  222.         int hflip = (data1 >> 15) & 1;
  223.         int vflip = (data1 >> 14) & 1;
  224.  
  225.         drawgfx(bitmap,Machine->gfx[1],
  226.                 pict,
  227.                 color,
  228.                 hflip,vflip,
  229.                 xpos,ypos,
  230.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  231.  
  232.         /* draw again with wraparound (needed to get the end of level animation right) */
  233.         drawgfx(bitmap,Machine->gfx[1],
  234.                 pict,
  235.                 color,
  236.                 hflip,vflip,
  237.                 xpos-256,ypos,
  238.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  239.     }
  240. }
  241.